using System;
using System.Collections.Generic;
using UnityEngine;

public class LiquidColorsDataManager
{
	private string path = "DataFiles/liquids_colors";

	private INIParser ini = new INIParser();

	private Dictionary<LiquidType, LiquidColorData> colorsData;

	public LiquidColorsDataManager()
	{
		LoadAllColors();
	}

	private void LoadAllColors()
	{
		LiquidType[] array = (LiquidType[])Enum.GetValues(typeof(LiquidType));
		colorsData = new Dictionary<LiquidType, LiquidColorData>();
		TextAsset name = Resources.Load<TextAsset>(path);
		ini.Open(name);
		for (int i = 0; i < array.Length; i++)
		{
			LoadColorsForLiquid(array[i]);
		}
		ini.Close();
	}

	private void LoadColorsForLiquid(LiquidType type)
	{
		string text = type.ToString();
		if (!ini.IsSectionExists(text))
		{
			if (type != 0)
			{
				UnityEngine.Debug.Log("Nie istnieje sekcja dla cieczy =" + text);
			}
			return;
		}
		if (!ini.IsKeyExists(text, "color"))
		{
			UnityEngine.Debug.Log("Nie istnieje klucz o nazwie 'color' dla cieczy =" + text);
			return;
		}
		string section = ini.ReadValue(text, "color", string.Empty);
		LiquidColorData liquidColorData = LoadColorsFromIni(type, section);
		if (liquidColorData != null)
		{
			colorsData.Add(type, liquidColorData);
		}
	}

	private LiquidColorData LoadColorsFromIni(LiquidType type, string section)
	{
		if (!ini.IsSectionExists(section))
		{
			if (type != 0)
			{
				UnityEngine.Debug.Log("Nie istnieje sekcja koloru o nazwie = " + section + " typ cieczy=" + type.ToString());
			}
			return null;
		}
		LiquidColorData liquidColorData = new LiquidColorData();
		liquidColorData.liquidType = type;
		Color color;
		bool flag = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "bottle_liquid", string.Empty), out color);
		liquidColorData.bottleLiquid = color;
		bool flag2 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "falling_liquid_background", string.Empty), out color);
		liquidColorData.fallingLiquidBackground = color;
		bool flag3 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "falling_liquid_foreground", string.Empty), out color);
		liquidColorData.fallingLiquidForeground = color;
		bool flag4 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "glass_liquid_base", string.Empty), out color);
		liquidColorData.glassLiquidBase = color;
		bool flag5 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "glass_liquid_brighter", string.Empty), out color);
		liquidColorData.glassLiquidBrighter = color;
		bool flag6 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "glass_liquid_brightest", string.Empty), out color);
		liquidColorData.glassLiquidBrightest = color;
		bool flag7 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "glass_liquid_base_shine", string.Empty), out color);
		liquidColorData.glassLiquidBaseShine = color;
		bool flag8 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "glass_liquid_brighter_shine", string.Empty), out color);
		liquidColorData.glassLiquidBrighterShine = color;
		bool flag9 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "glass_liquid_brightest_shine", string.Empty), out color);
		liquidColorData.glassLiquidBrightestShine = color;
		bool flag10 = ColorUtility.TryParseHtmlString(ini.ReadValue(section, "liquid_line", string.Empty), out color);
		liquidColorData.liquidLine = color;
		if (!flag || !flag2 || !flag3 || !flag4 || !flag5 || !flag6 || !flag7 || !flag8 || !flag9 || !flag10)
		{
			UnityEngine.Debug.Log("W sekcji= " + section + " któryś kolor jest niepoprawny");
			return null;
		}
		return liquidColorData;
	}

	public LiquidColorData GetColorDataForLiquid(LiquidType type)
	{
		if (colorsData.ContainsKey(type))
		{
			return colorsData[type];
		}
		return null;
	}
}
